<?php
if (!defined('APP') or !constant('APP')) die('Direct access not allowed!');

class View
{
    private static $template = "default";
    private static $variables = array();
    public static $LANG = array();
    
    private static $page_title = "";
    private static $keywords = "";
    private static $description = "";
    private static $root = "./template";
    private static $fbTags = "";
    
    public static function setFbTags(
            $fb_title,
            $fb_type,
            $fb_url,
            $fb_img,
            $fb_site_name,
            $fb_desc
            )
    {
        $config = Controller::getConfig();
        
        if (empty($fb_title)) $fb_title = $config['fb']['fb_title'];
        if (empty($fb_type)) $fb_type = $config['fb']['fb_type'];
        if (empty($fb_url)) $fb_url = $config['fb']['fb_url'];
        if (empty($fb_img)) $fb_img = $config['fb']['fb_img'];
        if (empty($fb_site_name)) $fb_site_name = $config['fb']['fb_site_name'];
        if (empty($fb_desc)) $fb_desc = $config['fb']['fb_desc'];
        
        $str  = '<meta property="og:title" content="'.$fb_title.'" />';
        $str .= '<meta property="og:type" content="'.$fb_type.'" />';
        $str .= '<meta property="og:url" content="'.$fb_url.'" />';
        $str .= '<meta property="og:image" content="'.$fb_img.'" />';
        $str .= '<meta property="og:site_name" content="'.$fb_site_name.'" />';
        $str .= '<meta property="og:description" content="'.$fb_desc.'"/>';
        
        self::$fbTags = $str;
    }
    
    public static function getFbTags()
    {
        return self::$fbTags;
    }
    
    
    public static function setRoot($root) { self::$root = $root; }
    public static function getRoot() { return self::$root; }
     
    public static function setPageTitle($title) { self::$page_title = $title; }
    public static function setKeywords($keywords) { self::$keywords = $keywords; }
    public static function setDescription($description) { self::$description = $description; }
    
    public static function getPageTitle() { return self::$page_title; }
    public static function getKeywords() { return self::$keywords; }
    public static function getDescription() { return self::$description; }


    public static function setLang($arr)
    {
        self::$LANG = $arr;
    }
    
    public static function content($name)
    {
        
        $file = "template/".self::$template."/".$name.".php";

        if (file_exists($file))
        {
            self::assign('content', System::get_include_contents($file));     
        }
        else
        {
            return false;
        }
    }
    
    public static function assign($key, $value)
    {
        self::$variables[$key] = $value;
    }
    
    public static function get($key)
    {
        $r = isset(self::$variables[$key]) ? self::$variables[$key] : "";
        return $r;
    }
    
    public static function template($name)
    {      
        self::$template = $name;
        return "./template/".$name."/";    
    }
    
    public static function render($name, $is_content = false)
    {  
        return "template/".self::$template."/".$name.".php";    
    }
    
    public static function getPath()
    {
        return self::$root."/template/".self::$template."/";   
    }
    
}

?>
